package com.example.zzl.view.fragment.ShareOrderFragment.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.example.zzl.R;
import com.example.zzl.view.fragment.ShareOrderFragment.adapter.ShareChoiceAdapter;
import com.example.zzl.view.fragment.ShareOrderFragment.disan.JsonAsyncTask;
import com.example.zzl.view.fragment.ShareOrderFragment.model.Choice;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;



/**
 * Created by Administrator on 2017/2/8.
 */

public class Newest extends Fragment {
    private ListView lv;
    private List<Choice> list;
    private List<Choice.InfolistBean> list1;
    private ShareChoiceAdapter adapter;

    private int pageIndex;//记录当前的页码
    private boolean isLoad;//记录是否需要加载下一页数据
    private String url="http://mws.biyabi.com/WebService.asmx/GetShareShoppingInfo?&Selected=1&UserID=0&TagURL&PageSize=10&Page=";

    private String baseUrl="http://mws.biyabi.com/WebService.asmx/GetShareShoppingInfo?&Selected=0&UserID=0&TagURL&PageSize=10&Page=1";
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.choiceness,null);
        lv=(ListView)view.findViewById(R.id.ch_lv);


        init();
        loadData();
        return view;
    }

    private void loadData() {
        new JsonAsyncTask(getContext(), new JsonAsyncTask.CallBack() {
            @Override
            public void sendData(String json) {
                Type type=new TypeToken<ArrayList<Choice>>(){}.getType();

                Object o = new Gson().fromJson(json, type);
                list=new Gson().fromJson(json, type);
                Choice choice = list.get(0);
                list1.addAll(choice.infolist);
                adapter.notifyDataSetChanged();
            }
        }).execute(baseUrl);


    }




    private void init() {

        list1=new ArrayList<>();
        adapter=new ShareChoiceAdapter(getContext(),list1);
        lv.setAdapter(adapter);

    }


}
